class Solution:
    def largestMerge(self, word1: str, word2: str) -> str:
        i,j,m,n = 0,0,len(word1),len(word2)
        merge = list()
        while i<m or j <n:
            if i <m and word1[i:] > word2[j:]:
                merge.append(word1[i])
                i+=1
            else:
                merge.append(word2[j])
                j+=1
        return "".join(merge)
if __name__ == '__main__':
    word1 = "cabaa"
    word2 = "bcaaa"
    solution = Solution()
    val = solution.largestMerge(word1,word2)
    print(val)